#include "helper/sqlite/FileDB.h"

#include <filesystem>
#include <system_error>

namespace helper {
namespace sqlite {

FileDB::FileDB(const std::string & name, const std::string & dir) 
: AbstractDB((std::filesystem::path(dir) / name).string())
{
}
FileDB::~FileDB(){
}

std::error_code FileDB::_open() {
  if(isMemoryUrl(url())){
    return std::make_error_code(std::errc::invalid_argument);
  }
  return AbstractDB::_open();
}
bool FileDB::exists() const {
  return std::filesystem::exists(url());
}
std::error_code FileDB::destroy(){
  AbstractDB::destroy();

  std::error_code ec;
  std::filesystem::remove(url(), ec);
  return ec;
}

}//namespace sqlite
}//namespace helper
